package day5.locks_demo;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 一个加锁的线程不释放锁，其它线程会一直处于阻塞状态
 */
public class Main1 {
    private static final Lock lock = new ReentrantLock();

    static class MyThread extends Thread {
        @Override
        public void run() {
            lock.lock();
            System.out.println("子线程进入临界区");     // 理论上，这句代码永远到达不了
        }
    }

    public static void main(String[] args) throws InterruptedException {
        lock.lock(); // 主线程获取到锁

        //lock.unlock();  // 如果主线程不释放锁，子线程永远不会执行

        MyThread t = new MyThread();
        t.start();

        t.join();

    }
}
